function [data]=diff_stack(data,template)

if nargin<2
    template=mean(data,3);
end


for ind=2:size(data,3)
    data(:,:,ind)=data(:,:,ind)-mean(mean(data(:,:,ind)));
end
template=mean(data,3);

for ind=2:size(data,3)
    data(:,:,ind)=data(:,:,ind)-template;
end
data(:,:,1)=data(:,:,2);